<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-model="open" width="600px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" style="padding-left: 10%" v-loading="loading">
      <el-form-item label="品牌名称:" prop="brandName">
        <el-input v-model="form.brandName"></el-input>
      </el-form-item>
      <el-form-item label="排序:" prop="sort">
        <el-input-number v-model="form.sort"></el-input-number>
      </el-form-item>
      <el-form-item label="状态:" prop="brandStatus">
        <el-radio-group v-model="form.brandStatus">
          <el-radio label="1">正常</el-radio>
          <el-radio label="0">隐藏</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm" :loading="loading">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import brand from '@/api/goods/brand';
import modelMixin from '@/mixins/modelMixin';
export default {
  name: 'addForm',
  mixins: [modelMixin],
  data() {
    return {
      funcObj: brand, //方法对象
      id: null, //必须配置，编辑需要赋值
      open: false,
      title: '添加品牌',
      form: {
        brandName: '',
        brandStatus: '1',
        sort: 0,
        remark: '1'
      },
      rules: {
        brandName: [{ required: true, message: '品牌名称不能为空', trigger: 'blur' }],
        sort: [{ required: true, message: '排序不能为空', trigger: 'blur' }],

        brandStatus: [{ required: true, message: '请选择状态', trigger: 'blur' }]
      }
    };
  },
  created() {},
  methods: {
    add() {
      this.id = null;
      this.open = true;
      this.form = {
        brandName: '',
        brandStatus: '1',
        sort: 0,
        remark: '1'
      };
      this.title = '添加品牌';
      this.getBrandSort();
      this.$refs.form.resetFields();
    },
    edit(row) {
      this.open = true;
      this.title = '编辑品牌';
      this.getDetail({ id: row.id });
    },
    cancel() {
      this.open = false;
    },
    categoryChange(value) {
      this.form.categoryId = value;
    },
    getBrandSort() {
      this.funcObj.getBrandSort().then((res) => {
        this.form.sort = +res.data.sort + 1;
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>